package com.Dao100;

import java.sql.*;
import com.Model100.*;
import com.Util100.*;

public class BookInformationDao100 {

	
	public ResultSet queryBookInfo(Connection conn, BookInformation100 bookInfo) {
		ResultSet rs = null;
		try {
			String sql = "select * from book100_information where book100_id = ?";
			PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql);
			pstmt.setInt(1, bookInfo.getBook100_id());
			rs = pstmt.executeQuery();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return rs;
	}
	
	
	public int addbookInfo(Connection conn, BookInformation100 bookInfo) {
		int res = -1;
		try {
			String sql = "insert into book100_information values(?,?,?,?,?)";
			PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql);

			pstmt.setInt(1, bookInfo.getBook100_id());
			pstmt.setString(2, bookInfo.getReader100_name());
			pstmt.setString(3, bookInfo.getBorrow100_data());
			pstmt.setString(4, bookInfo.getReturn100_data());
			pstmt.setString(5, bookInfo.getBook100_status());

			res = pstmt.executeUpdate();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}
	
	public int deletebookInfo(Connection conn,BookInformation100 bookInfo) 
	{
		int res=-1;
		try {
		String sql = "delete from book100_information where book100_id = ?";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setInt(1, bookInfo.getBook100_id());
		res= pstmt.executeUpdate();
	} catch (Exception e) {
		e.printStackTrace();
	}
		return res;
	}
}
